'''
	Input controller provide overridable methods for input controllers to use.
	
	@author: J.H. Donker
	@copyright: Twente University
'''
import wx

class InputController:
	'''
		Wraps third party input.
		
		@param inputInterface: The wrapper for the system.
		
		@version: 1.0
	''' 
	def __init__(self, inputInterface):
		self._inputInterface = inputInterface
		
	def Start(self):
		'''
			A start point of for third party input.
		
			@version: 1.0
		'''
		pass
		
	def Stop(self):
		'''
			A stop point for the third party input.
		
			@version: 1.0
		'''
		pass
		
	def GetName(self):
		'''
			Returns the name of the InputController.
		
			@return: The name.
		
			@version: 1.0
		'''
		return "InputControler"
		
# The base class is extended with a method to poll the interfaceaud 
class PolledInputController(InputController):
	'''
		The base class is extended with a method to poll the interface.
		This could be used to poll the device via the user interface.
		
		@version: 1.0
	'''
	def __init__(self, inputInterface):
		InputController.__init__(self, inputInterface)
		
	def Start(self):
		pass
	
		'''
			Polls the thing this InputController wraps.
		
			@version: 1.0
		'''
	def DoWork(self):
		pass
		
	def Stop(self):
		pass
		
	def GetName(self):
		return "PolledInputController"
				
class TimedInputController(PolledInputController):
	'''
		Extends the interface with a timer for timed polling.
		
		@version: 1.0
	'''
	def __init__(self, inputInterface, resolution):
		'''
			Constructor for the TimedInputController
			
			@param resolution: The timer resolution
		'''
		PolledInputController.__init__(self, inputInterface)
		self.__timer = wx.Timer(None, -1)
		self.__resolution = resolution
		self.__timer.Bind(wx.EVT_TIMER, self._onTick)
	

	def Start(self):
		'''
			Start polling
		
			@version: 1.0
		'''
		self.__timer.Start(self.__resolution)
	
	def _onTick(self, event):
		self.DoWork()

	def DoWork(self):
		pass
	

	def Stop(self):
		'''
			Stop polling.
		
			@version: 1.0
		'''
		self.__timer.Stop()
	

	def IsRunning(self):
		'''
			Checks if the controller is running.
		
			@return: True if running, false if not. 
		
			@version: 1.0
		'''
		return self.__timer.IsRunning()
				
	def GetName(self):
		return "TimedInputController"

	def GetResolution(self):
		'''
			Returns the polling interval resolution
		
			@return: Poll interval resolution
		
			@version: 1.0
		'''	
		return self.__resolution
